package hdservice;

import com.ht.aems.dbservice.ConnectionFactory;
import com.ht.aems.fesmodel.FesPersistenceFactory;
import com.ht.aems.fesmodel.persist.SqlPersistence;
import com.ht.log.LoggerUtil;
import com.ht.memcached.MemCachedConfigurator;
import devmodel.MOSqlPl;
import hdservice.impl.FesPointsChecker_sh;
import hdservice.impl.StatisticsAnlyzer_sh;
import hhh.remoteService.utils.ServiceRegister;
import hhh.remoteService.utils.rmi.RmiRegistry;
import hhh.utils.FileUtil;
import hhh.utils.LogUtil;
import rtdb.RtDataHandler_MemCached;
import rtdb.RtMeasureHandler_MemoCached;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date:2011-09-14
 */
public class Main4Open3000 {

    public static void main(String[] args) throws RemoteException, FileNotFoundException {
        LogUtil.initialLog4j("hdservice/hdservice.log");
        RmiRegistry.setSpecifiedSocket();

        //load memcached config file
        String f = FileUtil.getRootDirectory() + "/_config/memcache.properties";
        System.out.println("Load memcached config file : " + f);
        MemCachedConfigurator.config(f);

        //load database access config file
        f = FileUtil.getRootDirectory() + "/_config/dba.properties";
        System.out.println("Load database access config file : " + f);
        ConnectionFactory.setConfig(new FileInputStream(f));
        FesPersistenceFactory.setDatabase("shaems");
        FesPersistenceFactory.setType("sql");
        //initial log buffer
        LoggerUtil.initialBufferSize(100);

        HdSysModel.INSTANCE.setRtDataHandler(new RtDataHandler_MemCached());
        RtMeasureHandler_MemoCached rtMeasureHandle = new RtMeasureHandler_MemoCached();
        HdSysModel.INSTANCE.setRtMeasureQuery(rtMeasureHandle);
        HdSysModel.INSTANCE.setRtMeasureQuery(rtMeasureHandle);
        HdSysModel.INSTANCE.setCtrlDevPl(new MOSqlPl("AEMS_CTRL_DEVICES"));
        HdSysModel.INSTANCE.setFesPersistence(new SqlPersistence());

        RemoteHdFacade service = new RemoteHdFacade();
        service.setStatisticsAnalyzer(new StatisticsAnlyzer_sh());
        service.setFesPointsChecker(new FesPointsChecker_sh());

        ServiceRegister.registerService(HdFacade.class, service, "hdservice");
        System.out.println("history data service registered successfully!");
    }
}
